<?php

/**
 * Base presenter.
 *
 * @author David Dusek
 */

abstract class BasePresenter extends \Nette\Application\UI\Presenter {
    /**
     * Instance jadra systemu.
     * @var \CMS\Core
     */
    protected $core;
    
    /**
     * Etity manager.
     * @var Doctrine\ORM\EntityManager 
     */
    protected $em;
    
    protected function startup() {
        parent::startup();

        $core = \CMS\Core::getInstance();        
        $this->core = $core;        
        $this->em = $core->getEm();
                
        // nastaveni vychoziho layoutu
        $this->setLayout("layout");
    }
    
    /**
     * Metoda je prepsana aby bylo mozne pro admin cast pouzit jednotny
     * layout nezavisle na umisteni presentru.
     * @return type 
     */
    public function formatLayoutTemplateFiles()
    {
        $name = $this->getName();
        $presenter = substr($name, strrpos(':' . $name, ':'));
        $layout = $this->layout ? $this->layout : 'layout';
        $dir = APP_DIR; // tady se v Nette normalne ziskava cesta k aktualnimu souboru
        $list = array(
                "$dir/templates/$presenter/@$layout.latte",
                "$dir/templates/$presenter.@$layout.latte",
                "$dir/templates/$presenter/@$layout.phtml",
                "$dir/templates/$presenter.@$layout.phtml",
        );
        do {
                $list[] = "$dir/templates/@$layout.latte";
                $list[] = "$dir/templates/@$layout.phtml";
                $dir = dirname($dir);
        } while ($dir && ($name = substr($name, 0, strrpos($name, ':'))));
        return $list;
    }
}
